{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Imports\n",
    "\n",
    "Import all the modules and functionalities we need."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "\n",
    "# Import standard libraries.\n",
    "import os\n",
    "\n",
    "# Import third party libraries.\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "\n",
    "# Import custom libraries/scripts.\n",
    "import annotations\n",
    "import helpers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Loading data\n",
    "\n",
    "Fetch all our relevant data for the current analysis."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set working contants.\n",
    "EXPERIMENTS_PATH = r'\\\\10.40.12.80\\home\\PhD\\Results\\Competition\\DL\\small_arenas\\territory\\mating_pairs\\processed'\n",
    "FPS = 60\n",
    "N_MINUTES = 30\n",
    "N_FRAMES = N_MINUTES * 60 * FPS\n",
    "INK = 'black'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set figure configurations.\n",
    "sns.set(\n",
    "        context='paper',\n",
    "        style='ticks',\n",
    "        font='sans-serif',\n",
    "        font_scale=1.0, \n",
    "        rc={\n",
    "            'axes.axisbelow': True,\n",
    "            'axes.edgecolor': INK,\n",
    "            'axes.facecolor': 'white' if INK=='black' else 'black',\n",
    "            'axes.grid': False,\n",
    "            'axes.labelcolor': INK,\n",
    "            'axes.labelsize': 13.0,\n",
    "            'axes.labelweight': 'normal',\n",
    "            'axes.linewidth': 1.0,\n",
    "            'axes.spines.left': True,\n",
    "            'axes.spines.bottom': True,\n",
    "            'axes.spines.top': False,\n",
    "            'axes.spines.right': False,\n",
    "            'axes.titlepad': 15.0,\n",
    "            'axes.titlesize': 20.0,\n",
    "            'axes.titleweight': 'bold',\n",
    "            'figure.facecolor': 'white' if INK=='black' else 'black',\n",
    "            'figure.figsize': [3.0, 4.0],\n",
    "            'figure.titlesize': 30.0,\n",
    "            'figure.titleweight': 'bold',\n",
    "            'font.family': ['sans-serif'],\n",
    "            'font.sans-serif': ['Arial'],\n",
    "            'legend.frameon': False,\n",
    "            'legend.fontsize': 11.0,\n",
    "            'lines.color': INK,\n",
    "            'lines.linewidth': 1.0,\n",
    "            'patch.edgecolor': INK,\n",
    "            'savefig.dpi': 300,\n",
    "            'savefig.format': 'png',\n",
    "            'savefig.bbox': 'tight',\n",
    "            'savefig.transparent': True,\n",
    "            'text.color': INK,\n",
    "            'text.usetex': False,\n",
    "            'xtick.color': INK,\n",
    "            'xtick.direction': 'out',\n",
    "            'xtick.labelsize': 12.0,\n",
    "            'xtick.major.pad': 5.0,\n",
    "            'xtick.major.size': 0.0,\n",
    "            'xtick.major.width': 1.0,\n",
    "            'xtick.minor.size': 0.0,\n",
    "            'xtick.minor.width': 0.4,\n",
    "            'ytick.color': INK,\n",
    "            'ytick.direction': 'out',\n",
    "            'ytick.labelsize': 12.0,\n",
    "            'ytick.major.pad': 5.0,\n",
    "            'ytick.major.size': 3.0,\n",
    "            'ytick.major.width': 1.0,\n",
    "            'ytick.minor.size': 0.0,\n",
    "            'ytick.minor.width': 0.4\n",
    "           }\n",
    "       )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Folder already exists, skipping.\n"
     ]
    }
   ],
   "source": [
    "# Prepare the Figures folder to save our graphs in.\n",
    "savepath = os.path.join(r'C:\\Users\\Miguel\\Desktop\\paper_data', 'paper_figures', 'figureS3')\n",
    "try:\n",
    "    os.makedirs(savepath)\n",
    "    print('New folder created.')\n",
    "except FileExistsError:\n",
    "    print('Folder already exists, skipping.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Paths to conditions:\n",
      " ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor', '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory']\n"
     ]
    }
   ],
   "source": [
    "# Set the conditions to analyze.\n",
    "condition_order = ['food_odor', 'territory']\n",
    "conditions = [item.path for item in os.scandir(EXPERIMENTS_PATH) if item.name in condition_order]\n",
    "print('Paths to conditions:\\n', conditions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t\n",
      " food_odor\n",
      "Copulation too short: video_2022-05-11T11_46_58_arena5.csv\n",
      "\t\n",
      " territory\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'food_odor': ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena10.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_12_38_arena9.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena1.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena2.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena3.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena6.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T11_46_58_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena12.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena7.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-11T12_18_40_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena1.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena2.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena5.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T10_59_09_arena6.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena10.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena14.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena3.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena7.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\food_odor\\\\video_2022-05-12T11_34_40_arena9.csv'],\n",
       " 'territory': ['\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena1.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena2.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena3.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena5.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena6.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena7.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_12_38_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena10.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena11.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena12.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena14.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T11_46_58_arena9.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena1.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena10.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena14.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena2.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena5.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena6.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-11T12_18_40_arena9.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena10.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena13.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena3.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena4.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena7.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T10_59_09_arena8.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T11_34_40_arena15.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T11_34_40_arena16.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T11_34_40_arena5.csv',\n",
       "  '\\\\\\\\10.40.12.80\\\\home\\\\PhD\\\\Results\\\\Competition\\\\DL\\\\small_arenas\\\\territory\\\\mating_pairs\\\\processed\\\\territory\\\\video_2022-05-12T11_34_40_arena6.csv']}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Load all usable experiments for each condition.\n",
    "experiments = {condition: [] for condition in condition_order}\n",
    "\n",
    "for condition_path in conditions:\n",
    "    \n",
    "    condition = os.path.basename(condition_path)\n",
    "    print('\\t\\n', condition)\n",
    "    \n",
    "    for item in os.scandir(condition_path):\n",
    "        if item.name.endswith('.csv'):\n",
    "            \n",
    "            annotation_video = annotations.read(item.path)\n",
    "\n",
    "            try:\n",
    "                copulation = annotation_video[0].events[0]\n",
    "                copulation_duration = copulation.duration\n",
    "\n",
    "                # Filter out videos where copulation is interrupted.\n",
    "                copulation_end = copulation.time_interval[1]\n",
    "                if copulation_end==N_FRAMES and copulation_duration < 5 * 60 * FPS:\n",
    "                    print('Copulation interrupted:', item.name)\n",
    "                    continue\n",
    "\n",
    "                # Filter out videos where copulation lasts less than 8 minutes.\n",
    "                if copulation_duration <= 8 * 60 * FPS:\n",
    "                    print('Copulation too short:', item.name)\n",
    "                    continue\n",
    "            \n",
    "            except IndexError:\n",
    "                continue\n",
    "            \n",
    "            experiments[condition].append(item.path)\n",
    "\n",
    "experiments"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Aggression Analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iteration: 0 \n",
      "Experiment: video_2022-05-11T11_12_38_arena10 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 1 \n",
      "Experiment: video_2022-05-11T11_12_38_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 2 \n",
      "Experiment: video_2022-05-11T11_12_38_arena13 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 3 \n",
      "Experiment: video_2022-05-11T11_12_38_arena15 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 4 \n",
      "Experiment: video_2022-05-11T11_12_38_arena16 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 5 \n",
      "Experiment: video_2022-05-11T11_12_38_arena9 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 6 \n",
      "Experiment: video_2022-05-11T11_46_58_arena1 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 7 \n",
      "Experiment: video_2022-05-11T11_46_58_arena2 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 8 \n",
      "Experiment: video_2022-05-11T11_46_58_arena3 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 9 \n",
      "Experiment: video_2022-05-11T11_46_58_arena4 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 10 \n",
      "Experiment: video_2022-05-11T11_46_58_arena6 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 11 \n",
      "Experiment: video_2022-05-11T11_46_58_arena8 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 12 \n",
      "Experiment: video_2022-05-11T12_18_40_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 13 \n",
      "Experiment: video_2022-05-11T12_18_40_arena12 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 14 \n",
      "Experiment: video_2022-05-11T12_18_40_arena15 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 15 \n",
      "Experiment: video_2022-05-11T12_18_40_arena16 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 16 \n",
      "Experiment: video_2022-05-11T12_18_40_arena4 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 17 \n",
      "Experiment: video_2022-05-11T12_18_40_arena7 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 18 \n",
      "Experiment: video_2022-05-11T12_18_40_arena8 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 19 \n",
      "Experiment: video_2022-05-12T10_59_09_arena1 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 20 \n",
      "Experiment: video_2022-05-12T10_59_09_arena11 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 21 \n",
      "Experiment: video_2022-05-12T10_59_09_arena15 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 22 \n",
      "Experiment: video_2022-05-12T10_59_09_arena16 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 23 \n",
      "Experiment: video_2022-05-12T10_59_09_arena2 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 24 \n",
      "Experiment: video_2022-05-12T10_59_09_arena5 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 25 \n",
      "Experiment: video_2022-05-12T10_59_09_arena6 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 26 \n",
      "Experiment: video_2022-05-12T11_34_40_arena10 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 27 \n",
      "Experiment: video_2022-05-12T11_34_40_arena13 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 28 \n",
      "Experiment: video_2022-05-12T11_34_40_arena14 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 29 \n",
      "Experiment: video_2022-05-12T11_34_40_arena3 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 30 \n",
      "Experiment: video_2022-05-12T11_34_40_arena4 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 31 \n",
      "Experiment: video_2022-05-12T11_34_40_arena7 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 32 \n",
      "Experiment: video_2022-05-12T11_34_40_arena9 \n",
      "Condition: food_odor \n",
      "\n",
      "Iteration: 0 \n",
      "Experiment: video_2022-05-11T11_12_38_arena1 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 1 \n",
      "Experiment: video_2022-05-11T11_12_38_arena2 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 2 \n",
      "Experiment: video_2022-05-11T11_12_38_arena3 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 3 \n",
      "Experiment: video_2022-05-11T11_12_38_arena4 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 4 \n",
      "Experiment: video_2022-05-11T11_12_38_arena5 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 5 \n",
      "Experiment: video_2022-05-11T11_12_38_arena6 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 6 \n",
      "Experiment: video_2022-05-11T11_12_38_arena7 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 7 \n",
      "Experiment: video_2022-05-11T11_12_38_arena8 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 8 \n",
      "Experiment: video_2022-05-11T11_46_58_arena10 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 9 \n",
      "Experiment: video_2022-05-11T11_46_58_arena11 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 10 \n",
      "Experiment: video_2022-05-11T11_46_58_arena12 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 11 \n",
      "Experiment: video_2022-05-11T11_46_58_arena13 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 12 \n",
      "Experiment: video_2022-05-11T11_46_58_arena14 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 13 \n",
      "Experiment: video_2022-05-11T11_46_58_arena15 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 14 \n",
      "Experiment: video_2022-05-11T11_46_58_arena16 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 15 \n",
      "Experiment: video_2022-05-11T11_46_58_arena9 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 16 \n",
      "Experiment: video_2022-05-11T12_18_40_arena1 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 17 \n",
      "Experiment: video_2022-05-11T12_18_40_arena10 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 18 \n",
      "Experiment: video_2022-05-11T12_18_40_arena13 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 19 \n",
      "Experiment: video_2022-05-11T12_18_40_arena14 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 20 \n",
      "Experiment: video_2022-05-11T12_18_40_arena2 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 21 \n",
      "Experiment: video_2022-05-11T12_18_40_arena5 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 22 \n",
      "Experiment: video_2022-05-11T12_18_40_arena6 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 23 \n",
      "Experiment: video_2022-05-11T12_18_40_arena9 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 24 \n",
      "Experiment: video_2022-05-12T10_59_09_arena10 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 25 \n",
      "Experiment: video_2022-05-12T10_59_09_arena13 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 26 \n",
      "Experiment: video_2022-05-12T10_59_09_arena3 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 27 \n",
      "Experiment: video_2022-05-12T10_59_09_arena4 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 28 \n",
      "Experiment: video_2022-05-12T10_59_09_arena7 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 29 \n",
      "Experiment: video_2022-05-12T10_59_09_arena8 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 30 \n",
      "Experiment: video_2022-05-12T11_34_40_arena15 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 31 \n",
      "Experiment: video_2022-05-12T11_34_40_arena16 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 32 \n",
      "Experiment: video_2022-05-12T11_34_40_arena5 \n",
      "Condition: territory \n",
      "\n",
      "Iteration: 33 \n",
      "Experiment: video_2022-05-12T11_34_40_arena6 \n",
      "Condition: territory \n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>has_aggression</th>\n",
       "      <th>ratio_frames</th>\n",
       "      <th>ratio_bouts</th>\n",
       "      <th>condition</th>\n",
       "      <th>experiment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>0.012222</td>\n",
       "      <td>1.6</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>0.018500</td>\n",
       "      <td>1.4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>0.017000</td>\n",
       "      <td>0.8</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000333</td>\n",
       "      <td>0.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>0.014611</td>\n",
       "      <td>1.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001833</td>\n",
       "      <td>0.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T10_59_09_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>True</td>\n",
       "      <td>0.009833</td>\n",
       "      <td>1.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001222</td>\n",
       "      <td>0.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>True</td>\n",
       "      <td>0.016889</td>\n",
       "      <td>2.2</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>67 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    has_aggression  ratio_frames  ratio_bouts  condition  \\\n",
       "0             True      0.012222          1.6  food_odor   \n",
       "1             True      0.018500          1.4  food_odor   \n",
       "2             True      0.017000          0.8  food_odor   \n",
       "3             True      0.000333          0.2  food_odor   \n",
       "4             True      0.014611          1.2  food_odor   \n",
       "..             ...           ...          ...        ...   \n",
       "62            True      0.001833          0.8  territory   \n",
       "63            True      0.009833          1.8  territory   \n",
       "64            True      0.001222          0.8  territory   \n",
       "65           False      0.000000          0.0  territory   \n",
       "66            True      0.016889          2.2  territory   \n",
       "\n",
       "                           experiment  \n",
       "0   video_2022-05-11T11_12_38_arena10  \n",
       "1   video_2022-05-11T11_12_38_arena11  \n",
       "2   video_2022-05-11T11_12_38_arena13  \n",
       "3   video_2022-05-11T11_12_38_arena15  \n",
       "4   video_2022-05-11T11_12_38_arena16  \n",
       "..                                ...  \n",
       "62   video_2022-05-12T10_59_09_arena8  \n",
       "63  video_2022-05-12T11_34_40_arena15  \n",
       "64  video_2022-05-12T11_34_40_arena16  \n",
       "65   video_2022-05-12T11_34_40_arena5  \n",
       "66   video_2022-05-12T11_34_40_arena6  \n",
       "\n",
       "[67 rows x 5 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aggression_df = pd.DataFrame()\n",
    "for condition in experiments.keys():\n",
    "    for h, experiment_path in enumerate(experiments[condition]):\n",
    "\n",
    "        experiment = os.path.basename(experiment_path).split('.')[0]\n",
    "        \n",
    "        print('Iteration:', h, '\\nExperiment:', experiment, '\\nCondition:', condition, '\\n')\n",
    "        \n",
    "        # Exclude experiments without copulation (since aggression is only observed during copulation).\n",
    "        annotation_video = annotations.read(experiment_path)\n",
    "        try:\n",
    "            copulation = annotation_video[0].events[0]\n",
    "        except IndexError:\n",
    "            continue\n",
    "        \n",
    "        aggression_events = list(filter(lambda event: event.time < (copulation.time + 18000), annotation_video[1].events)) # Consider aggression only during the first 5 minutes of copulation.\n",
    "        n_events = len(aggression_events)\n",
    "\n",
    "        # In case there is aggression, do the necessary calculations.\n",
    "        if n_events > 0:\n",
    "            \n",
    "            aggression_latency =  aggression_events[0].time - copulation.time\n",
    "            aggression_latency_mins = aggression_latency / (60 * FPS)\n",
    "            \n",
    "            ratio_frames = sum([aggression.duration for aggression in aggression_events]) / (5 * 60 * FPS)\n",
    "            ratio_bouts = n_events / 5\n",
    "            \n",
    "            aggression_data = pd.DataFrame({'has_aggression': True,\n",
    "                                            'ratio_frames': ratio_frames,\n",
    "                                            'ratio_bouts': ratio_bouts,\n",
    "                                            'condition': condition,\n",
    "                                            'experiment': experiment},\n",
    "                                            index=[h],\n",
    "                                           )\n",
    "\n",
    "        # If not, preset our dictionary with default values.\n",
    "        else:\n",
    "            aggression_data = pd.DataFrame({'has_aggression': False,\n",
    "                                            'ratio_frames': 0, \n",
    "                                            'ratio_bouts': 0,\n",
    "                                            'condition': condition,\n",
    "                                            'experiment': experiment},\n",
    "                                            index=[h],\n",
    "                                           )\n",
    "\n",
    "        # Concatenate all data together.\n",
    "        aggression_df = pd.concat([aggression_df, aggression_data], ignore_index=True)\n",
    "\n",
    "aggression_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Outlier Detection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\t food_odor \n",
      "\n",
      "[7]\n",
      "Number data points considered outliers: 1\n",
      "Percent data points considered outliers: 3.03 %\n",
      "\n",
      "\t territory \n",
      "\n",
      "[43]\n",
      "Number data points considered outliers: 1\n",
      "Percent data points considered outliers: 2.941 %\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>has_aggression</th>\n",
       "      <th>ratio_frames</th>\n",
       "      <th>ratio_bouts</th>\n",
       "      <th>condition</th>\n",
       "      <th>experiment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>0.012222</td>\n",
       "      <td>1.6</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>0.018500</td>\n",
       "      <td>1.4</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>0.017000</td>\n",
       "      <td>0.8</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>0.000333</td>\n",
       "      <td>0.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>0.014611</td>\n",
       "      <td>1.2</td>\n",
       "      <td>food_odor</td>\n",
       "      <td>video_2022-05-11T11_12_38_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001833</td>\n",
       "      <td>0.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T10_59_09_arena8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>True</td>\n",
       "      <td>0.009833</td>\n",
       "      <td>1.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>True</td>\n",
       "      <td>0.001222</td>\n",
       "      <td>0.8</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>False</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>True</td>\n",
       "      <td>0.016889</td>\n",
       "      <td>2.2</td>\n",
       "      <td>territory</td>\n",
       "      <td>video_2022-05-12T11_34_40_arena6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>65 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    has_aggression  ratio_frames  ratio_bouts  condition  \\\n",
       "0             True      0.012222          1.6  food_odor   \n",
       "1             True      0.018500          1.4  food_odor   \n",
       "2             True      0.017000          0.8  food_odor   \n",
       "3             True      0.000333          0.2  food_odor   \n",
       "4             True      0.014611          1.2  food_odor   \n",
       "..             ...           ...          ...        ...   \n",
       "62            True      0.001833          0.8  territory   \n",
       "63            True      0.009833          1.8  territory   \n",
       "64            True      0.001222          0.8  territory   \n",
       "65           False      0.000000          0.0  territory   \n",
       "66            True      0.016889          2.2  territory   \n",
       "\n",
       "                           experiment  \n",
       "0   video_2022-05-11T11_12_38_arena10  \n",
       "1   video_2022-05-11T11_12_38_arena11  \n",
       "2   video_2022-05-11T11_12_38_arena13  \n",
       "3   video_2022-05-11T11_12_38_arena15  \n",
       "4   video_2022-05-11T11_12_38_arena16  \n",
       "..                                ...  \n",
       "62   video_2022-05-12T10_59_09_arena8  \n",
       "63  video_2022-05-12T11_34_40_arena15  \n",
       "64  video_2022-05-12T11_34_40_arena16  \n",
       "65   video_2022-05-12T11_34_40_arena5  \n",
       "66   video_2022-05-12T11_34_40_arena6  \n",
       "\n",
       "[65 rows x 5 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "corrected_ratio_frames = pd.DataFrame()\n",
    "\n",
    "for condition in condition_order:\n",
    "\n",
    "    print('\\n\\t', condition, '\\n')\n",
    "\n",
    "    try:\n",
    "        dataset = aggression_df.query('condition==\"' + condition + '\"')['ratio_frames']\n",
    "\n",
    "        outlier_positions = helpers.check_outliers(dataset)\n",
    "        print(outlier_positions)\n",
    "\n",
    "        fresh_dataset = pd.DataFrame(helpers.remove_outliers(dataset, indices=outlier_positions))\n",
    "        fresh_dataset['condition'] = condition\n",
    "\n",
    "        corrected_ratio_frames = pd.concat([corrected_ratio_frames, fresh_dataset], axis=0)\n",
    "        \n",
    "    except ValueError as error:\n",
    "        print(error)\n",
    "\n",
    "aggression_df = aggression_df.loc[corrected_ratio_frames.index]\n",
    "aggression_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Amount of Aggressive Bouts / Minute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>condition</th>\n",
       "      <th>ratio_bouts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>0.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>food_odor</td>\n",
       "      <td>1.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>territory</td>\n",
       "      <td>0.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>territory</td>\n",
       "      <td>1.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>territory</td>\n",
       "      <td>0.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>territory</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>territory</td>\n",
       "      <td>2.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>65 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    condition  ratio_bouts\n",
       "0   food_odor          1.6\n",
       "1   food_odor          1.4\n",
       "2   food_odor          0.8\n",
       "3   food_odor          0.2\n",
       "4   food_odor          1.2\n",
       "..        ...          ...\n",
       "62  territory          0.8\n",
       "63  territory          1.8\n",
       "64  territory          0.8\n",
       "65  territory          0.0\n",
       "66  territory          2.2\n",
       "\n",
       "[65 rows x 2 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_bouts_df = aggression_df.copy()\n",
    "ratio_bouts_df = ratio_bouts_df[['condition', 'ratio_bouts']]\n",
    "ratio_bouts_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\t territory \n",
      "\n",
      "Shapiro's Test: group 1 IS NOT normally distributed.\n",
      "D'Agostino's Test: group 1 IS NOT normally distributed.\n",
      "Shapiro's Test: group 2 IS NOT normally distributed.\n",
      "D'Agostino's Test: group 2 IS NOT normally distributed.\n",
      "Levene's Test for non-normally distributed samples:\n",
      "  p-value = 0.194453\n",
      "  All groups were sampled from populations with IDENTICAL variances.\n",
      "\n",
      "Mann-Whitney p-value: 0.19845707657214134 \n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'territory': 0.19845707657214134}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_bouts_pvalues = {}\n",
    "\n",
    "control = ratio_bouts_df.query('condition==\"food_odor\"')['ratio_bouts']\n",
    "\n",
    "for condition in condition_order[1:]:\n",
    "        \n",
    "    print('\\n\\t', condition, '\\n')\n",
    "\n",
    "    try:\n",
    "        test = ratio_bouts_df.query('condition==\"' + condition + '\"')['ratio_bouts']\n",
    "\n",
    "        temp_values = {'control': control, 'test': test}\n",
    "\n",
    "        pvalue_condition = helpers.run_statistics(temp_values)\n",
    "\n",
    "        ratio_bouts_pvalues[condition] = pvalue_condition\n",
    "        \n",
    "    except ValueError as error:\n",
    "        print(error)\n",
    "\n",
    "ratio_bouts_pvalues"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Effect Size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "territory\n",
      "Vestigial Effect: 0.0 \n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'territory': 0.0}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ratio_bouts_effect_sizes = {}\n",
    "\n",
    "control = ratio_bouts_df.query('condition==\"food_odor\"')['ratio_bouts']\n",
    "\n",
    "for condition in condition_order[1:]:\n",
    "    \n",
    "    print(condition)\n",
    "    \n",
    "    test = ratio_bouts_df.query('condition==\"' + condition + '\"')['ratio_bouts']\n",
    "\n",
    "    median_diff = helpers.get_effect_size(control, test, method='median_diff')\n",
    "    \n",
    "    ratio_bouts_effect_sizes[condition] = median_diff\n",
    "    \n",
    "ratio_bouts_effect_sizes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAALgAAAFHCAYAAAASgIa/AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nOydd3RU1dqHn8lk0hsJEEIqkAJphEAIhBYC0rsKCCogKja4HyCXa6N4LdfCtQKKKKiA4EWKKE1K6J2EEjoppJBKepu2vz+ioyEhTDCTGcJ51pq1ct45M+d3Tn7Zec/e+7xbJoQQSEg0UcyMLUBCwpBIBpdo0kgGl2jSSAaXaNJIBpdo0kgGl2jSNIrBZ8+ejZeXF2FhYYSFhTFu3LjGOKyEBOaNcZDDhw+zdu1aoqKiGuNwEhI6ZIYe6KmsrMTR0ZFBgwZx/fp1/P39+eijj/Dy8jLkYSUkgEZIUTIyM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j4+GBjY0NoaCiHDh2q9Xps2LCB4OBgnJyc6NevH1euXNG9N3fuXNzc3GjZsiWDBg0iMTGxYX4JDYnBV+K8z9i2bZvw8vISWq1WCCHE999/L7p06SKEEGLSpEli9uzZQoiqRV9DQkJEQUGBKCgoEF9//bXw9vYWV65cEYWFhWLEiBECEElJSSIpKUkAori4WOzdu1cA4t///rdQqVRiw4YNwszMTKSmptbQ8tfPCSHECy+8IB566CGRm5srsrOzRZ8+fcS8efOEEELMnz9fWFhYiAMHDgilUimio6OFjY2NOHTokCgrKxN9+vQRL7/8shBCiKeeekpMmDBBlJWVicrKSvH888+Lnj17CiGEWLFihejcubMQQohjx44JR0dHcfDgQaFUKsVHH30kfH19hVKpFLt27RLe3t4iNzdXqFQqMXXqVPHEE08Y8Ddzb0gGvw21Wi3c3NzEwYMHhRBCDB48WHzyySdCiJoGf/XVV3Wf69u3r/joo49025cuXbqjweVyuVAqlbp9HRwcxL59+2po+evntFqtsLa2FqdPn9a9HxsbK9zc3IQQVQaPjo7Wvff666+Lfv366bbfeOMN8eijjwohhLh586YoLCwUSqVSXLlyRbzyyiuiTZs2QojqBp82bZqYMWNGNU0+Pj5ix44d4sSJE8La2lr85z//EZcuXRIajUbva9yYSCnKbcjlciZMmMDatWvJzc0lNjaW8ePH17pvq1atdD9nZGTg6emp2/5jtbbacHJyQqFQ6LYVCkWNdTlvJycnh/LycqKjo3FycsLJyYkRI0aQn59PRUUFAM7OztXOw8nJSbdtZmamO0ZGRgZDhw6lVatWTJ48mXPnztV6/Bs3brBs2TLd8ZycnMjKyuLGjRt06dKFlStXsnXrVkJCQmjfvj2//vprnedgDKSbzFp48sknGTRoEEFBQcTExNCyZcta95PJZLqfPT09uXHjhm47LS2tQTW5uLhgYWFBXFyc7oaztLSUzMxMrKysauipi/HjxzNt2jT279+PTCbju+++49y5czX2c3NzY86cObz55pu62NWrV3F3dyc1NZWAgAD27dtHSUkJixcvZuzYsRQVFfH/7d2tqypBGMfxrwgWl0VBReEUNSi4GE2i/4AYxOLL6prMNotVEEHQ6EbTgmD0b7AIpi1iMYroqovRky/3hXMuC172zifPPMzAj4dhyuP1eh24sTNEB/+FbDZLOBxmOByiquqX9miaxmw2Y7/fY9v2X30n/onX66XRaNDv97ler9i2TbfbRdO0b9e63W74/X48Hg+maTIajX6a2AzQbrfRdZ3tdsvr9WK1WqEoCsfjkc1mQ6lU4nA4IEkSgUCAYDD4T4UbRMB/q9VqYVkW5XL5S+vr9Tq1Wo1cLkc6nSaZTALg8/kcO9N0OiUUCpHJZPj4+MCyLAzD+Had+XzOeDxGlmUqlQqapnE6nTifzz+sKxQKTCYTVFVFlmUGgwGGYZBKpahWq3Q6HfL5PJIkoes6y+XSqas6RgyCdchutyMSiRCLxQAwTRNFUXg8HmJ+/RuJDu6Q9XpNs9nkfr/zfD4ZjUYUi0UR7jcTAXdIr9cjHo+TSCSIRqNcLhcWi8W7j/XfE08UwdVEBxdcTQRccDURcMHVRMAFVxMBF1ztE3outz8mOEQDAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 180x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Initialize figure.\n",
    "n_conditions = ratio_bouts_df['condition'].nunique()\n",
    "figure, axis = plt.subplots(figsize=(1.25*n_conditions, 4))\n",
    "\n",
    "# Draw the boxplot.\n",
    "sns.boxplot(x='condition',\n",
    "            y='ratio_bouts',\n",
    "            data=ratio_bouts_df,\n",
    "            order=condition_order,\n",
    "            palette=['steelblue', '#5e6472'],\n",
    "            showfliers=False,\n",
    "            width=0.6,\n",
    "            boxprops={'edgecolor': INK},\n",
    "            medianprops={'color': INK},\n",
    "            whiskerprops={'color': INK},\n",
    "            capprops={'color': INK}\n",
    "           )\n",
    "\n",
    "# Draw the swarmplot.\n",
    "sns.swarmplot(x='condition',\n",
    "              y='ratio_bouts',\n",
    "              data=ratio_bouts_df,\n",
    "              order=condition_order,\n",
    "              palette=['steelblue', '#5e6472'],\n",
    "              linewidth=0.75,\n",
    "              edgecolor=INK\n",
    "             )\n",
    "\n",
    "# Figure and axes formatting.\n",
    "axis.set_xlabel('virgin females', labelpad=75)\n",
    "axis.set_xticklabels([''])\n",
    "axis.set_ylabel('# Bouts / Minute of Copulation')\n",
    "axis.set_ylim(0, 5)\n",
    "axis.set_yticks(range(0, 5+1, 1))\n",
    "axis.set_yticklabels(range(0, 5+1, 1))\n",
    "\n",
    "# Table definition.\n",
    "row1 = [str(ratio_bouts_df.query('condition==\"'+condition+'\"').shape[0]) for condition in condition_order]\n",
    "row2 = ['Food\\nodour', 'Territory']\n",
    "cell_text = np.array([row1, row2])\n",
    "\n",
    "row_labels = ['n =', '']\n",
    "summary_table = axis.table(cellText= cell_text,\n",
    "                           cellLoc='center',\n",
    "                           rowLabels=row_labels,\n",
    "                           rowLoc='center',\n",
    "                           colLoc='center'\n",
    "                          )\n",
    "\n",
    "summary_table.auto_set_font_size(False)\n",
    "summary_table.set_fontsize(11)\n",
    "\n",
    "properties = summary_table.properties()\n",
    "table_cells = properties['children']\n",
    "for cell in table_cells:\n",
    "    cell.set_height(0.12)\n",
    "    cell.set_alpha(0)\n",
    "    \n",
    "# Draw statistical results.\n",
    "for p, condition in enumerate(condition_order[1:]):\n",
    "    sig_height = 6 if (ratio_bouts_pvalues.get(condition, 'NaN') == 'NaN') or (ratio_bouts_pvalues.get(condition, 'NaN') >= 0.05) else 2\n",
    "    helpers.plot_stattest_result(ax=axis,\n",
    "                                 x1=p+1,\n",
    "                                 x2=p+1,\n",
    "                                 p_value=ratio_bouts_pvalues.get(condition, 'NaN'),\n",
    "                                 y=4.6,\n",
    "                                 ticksize=0,\n",
    "                                 xytext=(0,sig_height),\n",
    "                                 fontsize=13,\n",
    "                                 color=INK,\n",
    "                                 connector_color=INK\n",
    "                                )\n",
    "\n",
    "# Saving parameters.\n",
    "filename = 'nbouts_aggression_normalized_territory_mating_pairs'\n",
    "plt.savefig( os.path.join(savepath, filename))\n",
    "\n",
    "plt.show()\n",
    "plt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
